import 'package:boss/models/bill_summary.dart';
import 'package:boss/ui/page/reportForm/billSummary/provider/bill_summary_provider.dart';
import 'package:boss/ui/page/reportForm/billSummary/widget/bill_offers_panel.dart';
import 'package:boss/ui/widget/calendar_bar.dart';
import 'package:boss/ui/widget/loader/loader.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'bill_collection_panel.dart';

class BillSummaryBrowser extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Loader<BillSummary>(
      loadTask: Provider.of<BillSummaryProvider>(
        context,
        listen: false,
      ).queryBillSummary,
      builder: (context) {
        return SingleChildScrollView(
          padding: EdgeInsets.symmetric(
            horizontal: 30.w,
            vertical: 30.w,
          ),
          child: Consumer<BillSummaryProvider>(
            builder: (context, billSummaryProvider, _) => Column(
              children: <Widget>[
                CalendarBar(
                  startDateTime: billSummaryProvider.startDateTime,
                  endDateTime: billSummaryProvider.endDateTime,
                  onDateTimeChanged: billSummaryProvider.setEndDateTime,
                  type: CalendarType.ymdhm,
                ),
                BillCollectionPanel(),
                BillOffersPanel(
                  title: '堂食',
                  leftTitle: '优惠统计',
                  leftAmount: billSummaryProvider.billSummary.totalDiscountAmount,
                  centerTitle: '系统抹零',
                  centerAmount: billSummaryProvider.billSummary.sysDecreaseAmount,
                  rightTitle: '减免',
                  rightAmount: billSummaryProvider.billSummary.decreaseAmount,
                ),
                BillOffersPanel(
                  title: '外卖',
                  leftTitle: '优惠统计',
                  leftAmount: billSummaryProvider.billSummary.takeOutToalDiscountAmount,
                  centerTitle: '运费减免',
                  centerAmount: billSummaryProvider.billSummary.takeOutDeliverFreeFee,
                  rightTitle: '减免',
                  rightAmount: 0,
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
